Thread: define vs. char[]

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    46

    define vs. char[]

    Hi..

    Through my program i use some connections to sockets and it did seem to work earlier but not anymore after I changed define to char[].

    FROM:
    Code:
    define PORTlastNumber 6;
    define PORT  24006;
    define HOST "smr";
    define DIRSIZE 19000;//8192
    define SmrDemoAddress;
    TO:
    Code:
    int PORTlastNumber = 6;
    int PORT = 24006;
    char HOST[] = "smr";
    int DIRSIZE = 19000;//8192
    int SmrDemoAddress;
    I did it because I needed to use the portnumber elsewhere and made it global, but now it does not want proceed when reached Hostname, it simply stalls.. And I cannot write the value of HOST om the screen without it just stalls..
    Please help me..

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,674
    Well #defines don't normally have a ; at the end.

    Since your code worked with #defines at the end, it means there are an awful lot of them missing in your code.

    Say you had
    int myport = PORT
    With the define PORT 24006;
    this expands to
    int myport = 24006;

    But if you have just int PORT = 24006; then the attempt to use it is a syntax error.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    46
    Quote Originally Posted by Salem View Post
    Well #defines don't normally have a ; at the end.

    Since your code worked with #defines at the end, it means there are an awful lot of them missing in your code.

    Say you had
    int myport = PORT
    With the define PORT 24006;
    this expands to
    int myport = 24006;

    But if you have just int PORT = 24006; then the attempt to use it is a syntax error.
    Sorry, it was not the exact code.. Just one like it as I remembered it..

    Thanks, but I have found the problem.. There was no problem in this change.. The problem was that I had not defined the extern command right in the file where I should use it..

    the problem was:
    Code:
    extern HOST;  
    Should have been: 
    extern char HOST[]
    Such a litte thing screwed it all up.. Well thanks for your time..

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,674
    Great, another paraphrased question which heads off in entirely the wrong direction
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    May 2007
    Posts
    46

    Unhappy

    Quote Originally Posted by Salem View Post
    Great, another paraphrased question which heads off in entirely the wrong direction
    Sorry.. Thorght that the problem was due to the change from define to char[].. It seemed that way in my eyes...
    I did not potentially ask a question that was not related to the problem.. Sorry again..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer within a Struct
    By Bladactania in forum C Programming
    Replies: 11
    Last Post: 04-03-2009, 10:20 PM
  2. Need help with Bitmap Display
    By The Brain in forum Windows Programming
    Replies: 7
    Last Post: 03-23-2009, 05:33 AM
  3. Compiling error: Too many arguments.
    By Tuah in forum C++ Programming
    Replies: 16
    Last Post: 06-10-2008, 04:28 PM
  4. edit controls in dialogs
    By Homunculus in forum Windows Programming
    Replies: 10
    Last Post: 02-23-2006, 03:38 PM
  5. Please STICKY this- vital to MSVC 6 dev - BASETSD.h
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 03-15-2005, 09:22 AM